package com.hanter.demo.raddemo.test;

import android.content.Context;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * 屏幕工具类
 */
public class ScreenUtil {

	static public float getScreenDensity(Context context) {
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

		if (wm == null) {
			return DisplayMetrics.DENSITY_DEFAULT;
		} else {
			wm.getDefaultDisplay().getMetrics(dm);
			return dm.density;
		}
	}

	/**
	 * 获取屏幕分辨率
	 */
	public static Point getScreenSize(Context context) {
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Point point = new Point(0, 0);
		if (windowManager != null)
			windowManager.getDefaultDisplay().getSize(point);
		return point;
	}

	public static int getScreenWidth(Context context) {
		return getScreenSize(context).x;
	}

	public static int getScreenHeight(Context context) {
		return getScreenSize(context).y;
	}

}
